'use strict'
import { App, View } from '../../../component'
import style from './css.css'
import setTitle from '../../../config/setTitle'
import { observer, inject } from 'mobx-react'

@inject('user') @observer class Share extends React.Component {
  static propTypes = {
    user: PropTypes.object,
    history: PropTypes.object
  }
  _checkInviteCode = this._checkInviteCode.bind(this)
  handleChange = this.handleChange.bind(this)
  componentDidMount () {
    setTitle('输入邀请码')
  }
  handleChange (e) {
    const code = e.target.value
    // code = encodeURI(code)
    this.setState({ code })
  }

  _checkInviteCode () {
    const { code } = this.state
    this.props.user.checkInviteCode(code)
  }

  render () {
    return (
      <App noSysScroll={false}>
        <View className={style.inviteCode}>
          <View className={style.inputR}>
            <View className={style.text}>填写好友分享给你的邀请码</View>
            <input className={style.inputBtn} type='text' maxLength='10' placeholder='输入邀请码' onChange={this.handleChange} />
          </View>
          <View className={style.commitBtn} tap={this._checkInviteCode}>提交</View>
        </View>
      </App>
    )
  }
}

export default Share
